package com.qf.service.impl;

import com.qf.entity.Hotal;
import com.qf.feign.CityFeign;
import com.qf.mapper.HotalMapper;
import com.qf.service.IHotalService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HotalServiceImpl implements IHotalService {

    @Autowired
    private HotalMapper hotalMapper;

    @Autowired
    private CityFeign cityFeign;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    @Transactional
    public int saveHotal(Hotal hotal) {
        //同步修改城市的酒店数量
//        cityFeign.updateCityHotalNumber(hotal.getCid(), 1);

        int flag = hotalMapper.insert(hotal);
        //发布rabbitmq
        rabbitTemplate.convertAndSend("hotal_exchange", "", hotal);

        return flag;
    }

    @Override
    @Transactional(readOnly = true)
    public List<Hotal> list() {
        return hotalMapper.selectList(null);
    }

    /**
     * 调用该方法查询酒店
     * @param hid
     * @return
     */
    @Override
    @Transactional
    public Hotal getById(Integer hid) {

        //查询酒店信息以及相关的评论、房间....信息

        return hotalMapper.selectById(hid);
    }
}
